<template>
	<view>
		<view style="z-index: 2;">
			<u-loading-page :loading="loading"></u-loading-page>
		</view>
		<u-subsection :list="list" :current="current" @change="changeIndex"></u-subsection>
		<view>
			<view style="margin: 30rpx;">
				<view v-for="(item,index) in workList">
					<view style="display: flex;">
						<u--image :src="item.avatar" width="40px" height="40px" shape="circle"></u--image>
						<view style="display: flex;flex-direction: column;margin-left: 10rpx;">
							<text style="font-size: 30rpx;font-weight: bold;">{{item.name}}</text>
							<text style="font-size: 25rpx;">{{item.time}}</text>
						</view>
					</view>
					<view style="margin-top: 10rpx;font-size: 25rpx;display: flex;flex-direction: column;gap: 10rpx;">
						<text>提交作业了 来自</text>
						<text style="color: #3498db;font-weight: bold;">{{item.chapterName}}</text>
					</view>
					<view style="display: flex;gap: 30rpx;margin-top: 20rpx;">
						<u--image :src="work" width="100px" height="70px" v-for="(work,index) in item.url">
						</u--image>
					</view>
					<view>
						<text style="font-weight: bold;color: #7f8c8d;font-size: 35rpx;">讲师评论：{{item.comment}}</text>
					</view>
					<u-line margin="20rpx 0rpx 20rpx 0rpx"></u-line>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: ['广场',  '我的作业'],
				// 或者如下，也可以配置keyName参数修改对象键名
				// list: [{name: '未付款'}, {name: '待评价'}, {name: '已付款'}],
				current: 0,
				workList: [],
				loading:false
			}
		},

		onLoad() {
			this.getList()
		},
		methods: {
			changeIndex(e) {
				this.current = e;
				console.log(this.current);
				if(this.current==0){
					this.getList()
				}
				if(this.current==1){
					// this.getMyWork()
					uni.navigateTo({
						url:"/pages/workCircle/workList"
					})
				}
			},
			getMyWork(){
				// this.loading=true
				uni.$u.http.post('/user/info/myWork', "", {
					custom: {
						load: false,
						auth: true
					}
				}).then((res) => {
					this.workList = res;
					this.workList.forEach(item => {
						if (item.url) {
							let urlStr = item.url.replace(/\\(.)/mg, "$1");
							item.url = JSON.parse(urlStr)
						}
					})
					console.log("this.workList:", this.workList);
				}).catch((err) => {
					//联网失败, 结束加载
					console.log(err)
				})
			},
			getList() {
				this.loading=true
				uni.$u.http.post('/user/info/public/workList', "", {
					custom: {
						load: false,
						auth: true
					}
				}).then((res) => {
					this.loading=false
					this.workList = res;
					this.workList.forEach(item => {
						if (item.url) {
							let urlStr = item.url.replace(/\\(.)/mg, "$1");
							item.url = JSON.parse(urlStr)
						}
					})
					console.log("this.workList:", this.workList);
				}).catch((err) => {
					//联网失败, 结束加载
					console.log(err)
				})
			}
		}

	}
</script>

<style>

</style>
